home *** CD-ROM | disk | FTP | other *** search
/ Motor Sport Digital Archive Collection 1960s / Motor Sport Digital Archive Collection 1960s.iso / main.swf / scripts / mx / utils / Translator.as < prev    next >
Encoding:
Text File  |  2008-05-21  |  3.0 KB  |  97 lines

  1. package mx.utils
  2. {
  3.    import flash.system.ApplicationDomain;
  4.    import flash.utils.getQualifiedClassName;
  5.    import mx.resources.ResourceBundle;
  6.    
  7.    public class Translator
  8.    {
  9.       private static const TRANSLATORS:Object = new Object();
  10.       
  11.       private static var dataBundle:ResourceBundle = ResourceBundle.getResourceBundle("data",ApplicationDomain.currentDomain);
  12.       
  13.       private static var messagingBundle:ResourceBundle = ResourceBundle.getResourceBundle("messaging",ApplicationDomain.currentDomain);
  14.       
  15.       private static var rpcBundle:ResourceBundle = ResourceBundle.getResourceBundle("rpc",ApplicationDomain.currentDomain);
  16.       
  17.       private static var utilsBundle:ResourceBundle = ResourceBundle.getResourceBundle("utils",ApplicationDomain.currentDomain);
  18.       
  19.       private var bundle:ResourceBundle = null;
  20.       
  21.       private var bundleName:String;
  22.       
  23.       public function Translator(param1:String)
  24.       {
  25.          bundle = null;
  26.          super();
  27.          this.bundleName = param1;
  28.       }
  29.       
  30.       public static function getMessagingInstance() : Translator
  31.       {
  32.          return getInstanceFor("messaging");
  33.       }
  34.       
  35.       public static function getDefaultInstanceFor(param1:Class) : Translator
  36.       {
  37.          var _loc2_:String = null;
  38.          var _loc3_:int = 0;
  39.          var _loc4_:int = 0;
  40.          var _loc5_:int = 0;
  41.          var _loc6_:String = null;
  42.          _loc2_ = getQualifiedClassName(param1);
  43.          _loc3_ = int(_loc2_.indexOf("."));
  44.          _loc4_ = _loc3_ + 1;
  45.          _loc5_ = int(_loc2_.indexOf(".",_loc4_));
  46.          if(_loc5_ < 0)
  47.          {
  48.             _loc5_ = int(_loc2_.indexOf(":",_loc4_));
  49.          }
  50.          _loc6_ = _loc2_.slice(_loc4_,_loc5_);
  51.          return getInstanceFor(_loc6_);
  52.       }
  53.       
  54.       public static function getDataInstance() : Translator
  55.       {
  56.          return getInstanceFor("data");
  57.       }
  58.       
  59.       public static function getInstanceFor(param1:String) : Translator
  60.       {
  61.          var _loc2_:Translator = null;
  62.          _loc2_ = TRANSLATORS[param1];
  63.          if(_loc2_ == null)
  64.          {
  65.             _loc2_ = new Translator(param1);
  66.             TRANSLATORS[param1] = _loc2_;
  67.          }
  68.          return _loc2_;
  69.       }
  70.       
  71.       public function textOf(param1:String, ... rest) : String
  72.       {
  73.          if(bundle == null)
  74.          {
  75.             if(bundleName == "data")
  76.             {
  77.                this.bundle = dataBundle;
  78.             }
  79.             else if(bundleName == "messaging")
  80.             {
  81.                this.bundle = messagingBundle;
  82.             }
  83.             else if(bundleName == "rpc")
  84.             {
  85.                this.bundle = rpcBundle;
  86.             }
  87.             else if(bundleName == "utils")
  88.             {
  89.                this.bundle = utilsBundle;
  90.             }
  91.          }
  92.          return bundle == null ? "Key " + param1 + " was not found in resource bundle " + bundleName : StringUtil.substitute(bundle.getString(param1),rest);
  93.       }
  94.    }
  95. }
  96.  
  97.